package com.hds.modules.app.controller;


import com.hds.common.utils.PageUtils;
import com.hds.common.utils.R;
import com.hds.modules.app.annotation.LoginUser;
import com.hds.modules.app.annotation.Login;
import com.hds.modules.app.entity.UserEntity;
import com.hds.modules.sys.controller.AbstractController;
import com.hds.modules.sys.service.base.SysHdsShopGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * APP测试接口
 *
 * @date 2017-03-23 15:47
 */
@RestController
@RequestMapping("/app")
@Api("APP测试接口")
public class AppTestController extends AbstractController {

    @Autowired
    SysHdsShopGoodsService sysHdsShopGoodsService;


    @Login
    @GetMapping("userInfo")
    @ApiOperation("获取用户信息")
    public R userInfo(@LoginUser UserEntity user){
        logger.debug("====DEBUG====获取用户信息"+user);
        return R.ok().put("user", user);
    }

    @Login
    @GetMapping("userId")
    @ApiOperation("获取用户ID")
    public R userInfo(@RequestAttribute("userId") Integer userId){
        return R.ok().put("userId", userId);
    }

    @GetMapping("notToken")
    @ApiOperation("忽略Token验证测试")
    public R notToken(){
        logger.info("=====INFO====");
        return R.ok().put("msg", "无需token也能访问。。。");
    }


    @GetMapping("/goods/list")
    public R list(@LoginUser UserEntity user, @RequestParam Map<String, Object> params){
        PageUtils page = sysHdsShopGoodsService.queryPage(params);

        return R.ok().put("page", page);
    }

}
